import { Controller, Get, Inject,  } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import axios from 'axios';

@Controller("business")
export class AppController {
  constructor(
    // Inject中的参数必须对应注册子服务的名称
    @Inject('basic-service') private client: ClientProxy,
  ) {}

  @Get()
  getHello(): string {
    return '';
  }

  // 使用request/response请求响应的方式调用微服务1
  @Get('/business-to-basic-for-grpc')
  getBaseServiceForGrpc(): any {
    return this.client.send('basic', 'grpc');
  }

  // 使用request/response请求响应的方式调用微服务1
  @Get('/basic-service-http')
 async getBaseServiceForHttp() {
    console.log('basic-service微服务!');
    const serviceBUrl = 'http://localhost:10001';
    const response = await axios.get(serviceBUrl);
    // 处理响应
    return response.data;
  }
}
